function CommonUtil(){

}
/*当前环境变量的服务名称*/
CommonUtil.prototype.serverName = function(){
   if(typeof process!='undefined'){
       if(process.env.NODE_ENV == 'development'){
         return "/youyaboot-admin";
       }
   }
   //发布场景智能分析path
   var href = window.location.href.replace("https://","").replace("http://","");
   if(href.indexOf("/magicalcoder/")==-1){//来自开发环境
     return "/youyaboot-admin";
   }

   var pre = href.split("?")[0];
   var arr = pre.split("/magicalcoder/");
   if(arr[0].indexOf("/")==-1){
     return "";
   }
   var newArr = arr[0].split("/");
   newArr[0]="";
   var realPath = newArr.join("/");
   console.log(realPath);
   return realPath;
}
//自动处理服务名
CommonUtil.prototype.axiosWithServerName = function(type,url,params,callback){
     this.axios(type,this.serverName()+url,params,callback)
}
CommonUtil.prototype.axios = function(type,url,params,callback){
    axios[type](url,params,
        {headers:type=='post'?{'content-type':'application/json','charset':'UTF-8'}:''}
    ).then(function(response){
        if(!response.data.flag){
            layer.msg(response.data.desc);
            return
        }
        callback(response.data)
    })
    .catch(function(error) {
        console.log(error);
    })
}

CommonUtil.prototype.buildMcCondition = function(){
    return {type:"html",
        callback:{
            htmlCallback:function(param){
                return '<div class="layui-row layui-col-space3" id="mcConditionApp" v-if="show"><div class="layui-col-xs3">查询比较符</div><div class="layui-col-xs9"><el-select size="mini" @change="changeMe" v-model="mcCondition" placeholder="请选择比较条件"><el-option v-for="item in colorOpts" :key="item.k" :label="item.l" :value="item.k"></el-option></el-select></div></div>'
            },
            render:function (param) {
                //从magicalCoder获取当前聚焦节点的属性值 准备传入vue里
                var config = param.config,focusNode=param.focusNode;
                var mcCondition = focusNode.attributes['mc-condition'];
                if(mcCondition){
                      mcCondition = mcCondition.replace("&lt;","<").replace("&gt;",">");
                }
                //是否展示本次的数据
                var map = MAGICAL_CODER_API.getRootNodeMap({node:null});
                var pid = null;
                var show = false;
                var maxCeng = 0;
                var node =focusNode;
                while(true){
                    pid = node.magicalCoder.parentId;
                    if(!pid){
                        break;
                    }
                    node = map[pid];
                    if(node.magicalCoder.tagName=='template' && node.attributes['v-slot:query']){
                        show = true;
                        break;
                    }
                    if(maxCeng++ >100){
                        break;
                    }
                }


                new Vue({
                    el: '#mcConditionApp',
                    data: {
                        mcCondition:mcCondition,
                        show:show,
                        colorOpts:[
                            {k:"",l:"请选择"},
                            {k:"<",l:"小于"},
                            {k:"<=",l:"小于等于"},
                            {k:"=",l:"等于"},
                            {k:">",l:"大于"},
                            {k:">=",l:"大于等于"},
                            {k:"!=",l:"不等于"},
                            {k:"like",l:"包含like"},
                            {k:"not like",l:"不包含"},
                            {k:"in",l:"IN"},
                            {k:"not in",l:"NOT IN"},
                            {k:">>",l:"右移"},
                            {k:"<<",l:"左移"},
                        ]
                    },
                    methods:{
                        changeMe:function (newValue) {
                            MAGICAL_CODER_API.changeAttr({node:focusNode,name:'mc-condition',value:newValue,triggerChange:false});
                        }
                    }
                })
            }
        }
    };
}
CommonUtil.prototype.isKeepWord = function (value){
  var keepwords = [
    "add","all","alter","analyze","and","as","asc","auto_increment","bdb","before","berkeleydb","between","bigint","binary","blob","both","btree","by","cascade","case","change","char","character","check","collate","column","columns","constraint","create","cross","current_date","current_time","current_timestamp","database","databases","day_hour","day_minute","day_second","dec","decimal","default","delayed","delete","desc","describe","distinct","distinctrow","div","double","drop","else","enclosed","errors","escaped","exists","explain","false","fields","float","for","force","foreign","from","fulltext","function","grant","group","hash","having","high_priority","hour_minute","hour_second","if","ignore","in","index","infile","inner","innodb","insert","int","integer","interval","into","is","join","key","keys","kill","leading","left","like","limit","lines","load","localtime","localtimestamp","lock","long","longblob","longtext","low_priority","master_server_id","match","mediumblob","mediumint","mediumtext","middleint","minute_second","mod","mrg_myisam","natural","not","null","numeric","on","optimize","option","optionally","or","order","outer","outfile","precision","primary","privileges","procedure","purge","read","real","references","regexp","rename","replace","require","restrict","returns","revoke","right","rlike","rtree","select","set","show","smallint","some","soname","spatial","sql_big_result","sql_calc_found_rows","sql_small_result","ssl","starting","straight_join","striped","table","tables","terminated","then","tinyblob","tinyint","tinytext","to","trailing","true","types","union","unique","unlock","unsigned","update","usage","use","user_resources","using","values","varbinary","varchar","varcharacter","varying","warnings","when","where","with","write","xor","year_month","zerofill",
    "abstract", "assert", "boolean", "break", "byte",
    "case", "catch", "char", "class", "const",
    "continue", "default", "do", "double", "else",
    "enum", "extends", "final", "finally", "float",
    "for", "goto", "if", "implements", "import",
    "instanceof", "int", "interface", "long", "native",
    "new", "package", "private", "protected", "public",
    "return", "short", "static", "strictfp", "super",
    "switch", "synchronized", "this", "throw", "throws",
    "transient", "try", "void", "volatile", "while"]
  for(var i in keepwords){
    if(value===keepwords[i]){
      return true;
    }
  }
  return false;
}
var CommonUtil = new CommonUtil();
